﻿using System.Linq;
using Web.Components;
using SilenthinkContract.Domain;
using System.Collections.Generic;

namespace Web.Areas.Cart.Models
{
    public static class CheckoutControllerModel
    {
        public class Index
        {
            public byte Param { get; set; }
            public IList<Location> Locations { get; set; }

            public ShoppingCart ShoppingCart { get; set; }

            public IList<UserInvoice> UserInvoices { get; set; }

            public IList<UserAddress> UserAddresses { get; set; }

            public string GetLocationName(string areaCode)
            {
                var provinceCode = areaCode.Substring(0, 2);
                var province = Locations.FirstOrDefault(o => o.LocationCode == provinceCode);
                var provinceName = province != null ? province.LocationName : string.Empty;

                var cityCode = areaCode.Substring(0, 4);
                var city = Locations.FirstOrDefault(o => o.LocationCode == cityCode);
                var cityName = city != null ? city.LocationName : string.Empty;

                var area =
                    Locations.FirstOrDefault(o => o.LocationCode == areaCode || o.LocationCode == areaCode + "000000");
                var areaName = area != null ? area.LocationName : string.Empty;

                return string.Format("{0} {1} {2}", provinceName, cityName, areaName);

            }

        }
    }
}